package serviceparameterisunique;

import org.eclipse.emf.ecore.EObject;

import org.eclipse.viatra2.emf.incquery.validation.runtime.Constraint;
import org.eclipse.viatra2.emf.incquery.validation.runtime.ValidationUtil;
import org.eclipse.viatra2.emf.incquery.runtime.api.impl.BaseGeneratedMatcherFactory;
import serviceparameterisunique.ServiceParameterIsUniqueMatch;
import serviceparameterisunique.ServiceParameterIsUniqueMatcherFactory;
import serviceparameterisunique.ServiceParameterIsUniqueMatcher;

public class ServiceParameterIsUniqueConstraint extends Constraint<ServiceParameterIsUniqueMatch> {

	private ServiceParameterIsUniqueMatcherFactory matcherFactory;

	public ServiceParameterIsUniqueConstraint() {
		matcherFactory = new ServiceParameterIsUniqueMatcherFactory();
	}

	@Override
	public String getMessage() {
		return "$service.name$ service has more than one parameter named $serviceParameter.name$. Service parameter names should be unique!";
	}

	@Override
	public EObject getLocationObject(ServiceParameterIsUniqueMatch signature) {
		Object location = signature.get("service");
		if(location instanceof EObject){
			return (EObject) location;
		}
		return null;
	}
	
	@Override
	public int getSeverity() {
		return ValidationUtil.getSeverity("error");
	}
	
	@Override
	public BaseGeneratedMatcherFactory<ServiceParameterIsUniqueMatch, ServiceParameterIsUniqueMatcher> getMatcherFactory() {
		return matcherFactory;
	}
}
